package com.software.chemistry.controller;

import com.software.chemistry.domain.Result;
import com.software.chemistry.entity.ModelInfo;
import com.software.chemistry.entity.ModelType;
import com.software.chemistry.service.ModelInfoService;
import com.software.chemistry.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import java.util.List;

@RestController
@RequestMapping("/model_info")
public class ModelInfoController {
    @Autowired
    private ModelInfoService modelInfoService;

    //分页查询常见模型
    @GetMapping("/findCommonModelInfo")
    public Result<ModelInfo> findCommonModelInfo(@RequestParam(name = "page") int page,
                                                       @RequestParam(name = "size") int size){
        if(page < 1){
            return ResultUtil.error("500", "当前页码不能小于1", null);
        }
        Pageable pageable = PageRequest.of(page-1, size);
        List<ModelInfo> pageResult = modelInfoService.findCommonModelInfo(pageable);
        return ResultUtil.success(pageResult);
    }

    @GetMapping("/findModelInfoByTypeId/{typeId}")
    private Result<ModelInfo> findModelInfoByTypeId(@PathVariable String typeId){
        List<ModelInfo> pageResult = modelInfoService.findModelInfoByTypeId(typeId);
        return  ResultUtil.success(pageResult);
    }

    @GetMapping("/findByModelNameOrModelDescription/{obtain}")
    private Result<ModelInfo> findByModelNameOrModelDescription(@PathVariable String obtain){
        List<ModelInfo> modelInfos = modelInfoService.findByModelNameOrModelDescription(obtain);
        return ResultUtil.success(modelInfos);
    }

}
